﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using T.FAS.Runtime.UserProfile.Entity;
using T.ServiceComponent.DAC.Service;

namespace T.FAS.Runtime.UserProfile.Dao
{
    public class UserProfilesDao : DaoService<UserProfiles>
    {
        public UserProfilesDao() :
          base()
        {
            DBName = "TFAS";
        }

        public override string IDColumnName => "ID";
        public override string TableName => "FAS_UserProfiles";
        public override List<string> ExceptColumnName => new List<string> { "ItemCode", "ItemName", "ItemDescription", "ItemHelpID" };

        public UserProfiles GetUserProfile(string profileItemID)
        {
            var result = new List<UserProfiles>();
            List<object> objects = base.GetObjectsByFilter(string.Format("ItemID='{0}'  and UserID = '{1}'", profileItemID, UserUtil.GetCurrentUserID()));
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as UserProfiles));
            }
            return result.FirstOrDefault();
        }
        public List<UserProfiles> GetUserProfiles(string profileGroupID)
        {
            var result = new List<UserProfiles>();
            List<object> objects = base.GetObjectsByFilter(string.Format("ItemID in (select ID from FAS_UserProfileItem where groupID = '{0}') and UserID = '{1}'", profileGroupID, UserUtil.GetCurrentUserID()));
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as UserProfiles));
            }
            return result;
        }
        public void DeleteUserProfiles(string profileItemID)
        {
            string sql = string.Format("delete from {0} where ItemID = '{1}' and UserID = '{2}'", TableName ,profileItemID, UserUtil.GetCurrentUserID());
            DB.ExecSqlStatement(sql);
        }
    }
}
